Fix uniqueness test for WebsiteAgent

Andrew Cantino 12 years ago
parent
commit
6559d79a51
1 changed files with 4 additions and 4 deletions
  1. 4 4
      app/models/agents/website_agent.rb

+ 4 - 4
app/models/agents/website_agent.rb

@@ -30,7 +30,7 @@ module Agents
30 30
             :description => { :path => "results.data[*].description" }
31 31
           }
32 32
 
33
-      Note that for all of the formats, whatever you extract MUST have the same number of matches for each extractor.  E.g., if you're extracting rows, all extractors must match all rows.
33
+      Note that for all of the formats, whatever you extract MUST have the same number of matches for each extractor.  E.g., if you're extracting rows, all extractors must match all rows.  For generating CSS selectors, something like [SelectorGadget](http://selectorgadget.com) may be helpful.
34 34
 
35 35
       Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
36 36
     MD
@@ -94,15 +94,15 @@ module Agents
94 94
 
95 95
         raise StandardError, "Got an uneven number of matches for #{options[:name]}: #{options[:extract].inspect}" unless num_unique_lengths.length == 1
96 96
 
97
-        previous_payloads = events.order("id desc").limit(UNIQUENESS_LOOK_BACK).pluck(:payload) if options[:mode].to_s == "on_change"
97
+        previous_payloads = events.order("id desc").limit(UNIQUENESS_LOOK_BACK).pluck(:payload).map(&:to_json) if options[:mode].to_s == "on_change"
98 98
         num_unique_lengths.first.times do |index|
99 99
           result = {}
100 100
           options[:extract].keys.each do |name|
101 101
             result[name] = output[name][index]
102 102
           end
103 103
 
104
-          if !options[:mode] || options[:mode].to_s == "all" || (options[:mode].to_s == "on_change" && !previous_payloads.include?(result))
105
-            Rails.logger.info "Storing new result for '#{options[:name]}': #{result.inspect}"
104
+          if !options[:mode] || options[:mode].to_s == "all" || (options[:mode].to_s == "on_change" && !previous_payloads.include?(result.to_json))
105
+            Rails.logger.info "Storing new result for '#{name}': #{result.inspect}"
106 106
             create_event :payload => result
107 107
           end
108 108
         end